programming4us
           
 
 
SQL Server

SQL Server 2008: SQL Server Service Broker - Related System Catalogs

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
1/2/2011 11:43:39 AM
A few of the system catalogs and dynamic management views (DMVs) might be of interest to you if you’re debugging Service Broker applications or simply seeking a greater understanding of how Service Broker works under the hood. Let’s take a look at some of them.

You’ve already seen sys.transmission_queue, which is used to store undelivered messages in a particular database. This table is very useful because it provides the reason a message is undeliverable (in transmission_status), the date sent (in enqueue_time), a conversation identifier (conversation_handle), contract and service names (service_contract_name, to_service_name, from_service_name), and more.

Another useful catalog is sys.service_queues, which holds the definitions of the queues defined in a particular database. It has a few interesting columns:

  • activation_procedure— This column contains the name of the activated service program that is bound to the queue.

  • max_readers— This column contains the integer value specified in the CREATE QUEUE of MAX_QUEUE_READERS.

  • is_retention_enabled— This column contains the Boolean value of the RETENTION flag in CREATE QUEUE.

You can use the value in the object_id column to figure out which queue is being referenced in a particular error message, such as the following, which you may find in your transmission queue someday: This message could not be delivered because the destination queue has been disabled. Queue ID: 325576198. This error occurs when your activated code throws an error in its body after receiving a message, rolls back the receive, is activated again, and so on, until Service Broker intervenes and disables the queue. (It usually takes three failures for this to happen.) A similar error is raised if you set ENCRYPTION = ON and don’t set up certificates.

To see all the services in a particular database, you can query sys.services. To see all the active conversations, you can query sys.conversation_groups. The following query shows how to use these tables together:

SELECT
sq.name as QueueName,
ss.name as ServiceName,
cg.conversation_group_id as CGId
FROM sys.services ss
JOIN sys.service_queues sq
ON ss.service_queue_id = sq.object_id
LEFT JOIN sys.conversation_groups cg
ON cg.service_id = ss.service_id

To see all the contracts in a particular database, you can query sys.service_contracts. To see all the message types, you can query sys.service_message_types. These catalog views are brought together in the system table sys.service_contract_message_usages (showing message types by contract). You can also link them to sys.service_contract_usages (showing contracts by service) via the following query:

SELECT
s.Name ServiceName,
sc.Name ContractName,
smt.Name as MsgTypeName,
scmu.is_sent_by_initiator,
scmu.is_sent_by_target
FROM sys.services s
JOIN sys.service_contract_usages scu
ON scu.service_id = s.service_id
JOIN sys.service_contracts sc
ON sc.service_contract_id = scu.service_contract_id
JOIN sys.service_contract_message_usages scmu
ON scmu.service_contract_id = sc.service_contract_id
JOIN sys.service_message_types smt
ON smt.message_type_id = scmu.message_type_id

In addition, you can view any certificates you have created by querying sys.certificates, routes via sys.routes, and remote service bindings via sys.remote_service_bindings. Each side of a conversation is known as an endpoint, and you can view endpoints by querying sys.conversation_endpoints.

Five DMVs may be of interest in debugging live Service Broker applications:

  • sys.dm_broker_activated_tasks— Each row refers to a stored procedure being activated.

  • sys.dm_broker_connections— Each row refers to an in-use Service Broker network connection.

  • sys.dm_broker_forwarded_messages— Each row refers to a message currently being forwarded.

  • sys.dm_broker_queue_monitors— Each row refers to the current behavior of a SQL Server background task known as a queue monitor, which is responsible for activation.

  • sys.dm_broker_transmission_status— Each row refers to the status of a message being transmitted.

To see all the activated stored procedures in a given database, for example, you can try the following:

SELECT
d.name DBName,
sq.name QueueName,
dmbat.spid SPID,
dmbat.procedure_name ProcName
FROM sys.dm_broker_activated_tasks dmbat
JOIN sys.databases d ON
d.database_id = dmbat.database_id
AND dmbat.database_id = DB_ID()
JOIN sys.service_queues sq
ON dmbat.queue_id = sq.object_id

Other -----------------
- SQL Azure Backup Strategies (part 2)
- SQL Azure Backup Strategies (part 1) - Copying a Database
- SQL Server 2008: Troubleshooting SSB Applications with ssbdiagnose.exe
- SQL Server 2008: Service Broker Routing and Security
- Migrating Databases and Data to SQL Azure (part 9)
- Migrating Databases and Data to SQL Azure (part 8)
- Understanding Service Broker Constructs (part 5)
- Understanding Service Broker Constructs (part 4) - Creating the Conversation Initiator
- Migrating Databases and Data to SQL Azure (part 7)
- Migrating Databases and Data to SQL Azure (part 6) - Building a Migration Package
- Migrating Databases and Data to SQL Azure (part 5) - Creating an Integration Services Project
- Understanding Service Broker Constructs (part 3)
- Understanding Service Broker Constructs (part 2) - Creating Queues for Message Storage
- Understanding Service Broker Constructs (part 1) - Defining Messages and Choosing a Message Type
- SQL Server 2008 : SQL Server Service Broker - Designing a Sample System
- Migrating Databases and Data to SQL Azure (part 4) - Fixing the Script
- Migrating Databases and Data to SQL Azure (part 3) - Reviewing the Generated Script
- SQL Server 2008 : SQL Server Service Broker - Understanding Distributed Messaging
- SQL Server 2008 : Full-Text Search Troubleshooting
- Migrating Databases and Data to SQL Azure (part 2)
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us